package com.qijian.common.utils.sync;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qijian.common.utils.StringUtils;
import lombok.Data;

@Data
public class PurchaseAttrGD {

    /**
     * 材质
     */
    String caizhi;
    /**
     * 厚
     */
    String hou;
    /**
     * 宽
     */
    String kuan;
    /**
     * 长
     */
    String chang;
    /**
     * 品牌
     */
    String pinpai;
    /**
     * 规格型号
     */
    String guigexinghao;
    /**
     * 库存项目
     */
    String kucunxiangmu;

    /**
     * 复试
     */
    String fushi;
    /**
     * 库存备注
     */
    String kucunbeizhu;
    /**
     * 包装方式
     */
    String baozhuangfangshi;
    /**
     * PO号装配
     */
    String pohaozhuangpei;

    /**
     * 牌号
     */
    String paihao;

    /**
     * 标准件规格
     */
    String biaozhunjianguige;

    /**
     * 性能等级
     */
    String xingnengdengji;

    /**
     * 表面处理名称
     */
    String biaomianchuli;

    /**
     * 表面处理编码
     */
    String biaomianchuliBm;

    /**
     * 规格/品牌
     */
    String guigepinpai;

    /**
     * 型号/材质
     */
    String xinghaocaizhi;

    /**
     * 色号
     */
    String sehao;

    /**
     * 特殊要求
     */
    String teshuyaoqiu;

    /**
     * 标准件长度
     */
    String biaozhunjianchangdu;


    public static PurchaseAttrGD build(JSONObject x) {
        PurchaseAttrGD attr = new PurchaseAttrGD();
        attr.setCaizhi(x.getString("FAUXPROPID.FF100001.fdatavalue"));
        attr.setHou(x.getString("FAUXPROPID.FF100002.fdatavalue"));
        attr.setKuan(x.getString("FAUXPROPID.FF100003"));
        attr.setChang(x.getString("FAUXPROPID.FF100004"));
        attr.setPinpai(x.getString("FAUXPROPID.FF100005.fdatavalue"));
        attr.setGuigexinghao(x.getString("FAUXPROPID.FF100006.fdatavalue"));
        attr.setKucunxiangmu(x.getString("FAUXPROPID.FF100007"));
        attr.setFushi(x.getString("FAUXPROPID.FF100008"));
        attr.setKucunbeizhu(x.getString("FAUXPROPID.FF100009"));
        attr.setBaozhuangfangshi(x.getString("FAUXPROPID.FF100011.FDATAVALUE"));
        attr.setPohaozhuangpei(x.getString("FAUXPROPID.FF100013"));
        attr.setPaihao(x.getString("FAUXPROPID.FF100015.fdatavalue"));
        attr.setBiaozhunjianguige(x.getString("FAUXPROPID.FF100016.fdatavalue"));
        attr.setXingnengdengji(x.getString("FAUXPROPID.FF100017.fdatavalue"));
        attr.setBiaomianchuli(x.getString("FAUXPROPID.FF100018.fdatavalue"));
        attr.setBiaomianchuliBm(x.getString("FAUXPROPID.FF100018.FNUMBER"));
        attr.setGuigepinpai(x.getString("FAUXPROPID.FF100019.fdatavalue"));
        attr.setXinghaocaizhi(x.getString("FAUXPROPID.FF100020.fdatavalue"));
        attr.setSehao(x.getString("FAUXPROPID.FF100021"));
        attr.setTeshuyaoqiu(x.getString("FAUXPROPID.FF100022"));
        attr.setBiaozhunjianchangdu(x.getString("FAUXPROPID.FF100023"));
        return attr;
    }

    public static PurchaseAttrGD buildStr(JSONObject x) {
        PurchaseAttrGD attr = new PurchaseAttrGD();
        attr.setCaizhi(x.getString("材质"));
        attr.setHou(x.getString("厚"));
        attr.setKuan(x.getString("宽"));
        attr.setChang(x.getString("长"));

        attr.setPinpai(x.getString("品牌"));
        attr.setGuigexinghao(x.getString("规格型号"));
        attr.setKucunxiangmu(x.getString("库存项目"));
        attr.setFushi(x.getString("复试"));

        attr.setKucunbeizhu(x.getString("库存备注"));
        attr.setBaozhuangfangshi(x.getString("包装方式"));
        attr.setPohaozhuangpei(x.getString("PO号装配"));


        attr.setPaihao(x.getString("牌号"));

        attr.setBiaozhunjianguige(x.getString("标准件规格"));
        attr.setXingnengdengji(x.getString("性能等级"));
        attr.setBiaomianchuli(x.getString("表面处理"));

        attr.setGuigepinpai(x.getString("规格/品牌"));

        attr.setXinghaocaizhi(x.getString("型号/材质"));
        attr.setSehao(x.getString("色号"));
        attr.setTeshuyaoqiu(x.getString("特殊要求"));
        attr.setBiaozhunjianchangdu(x.getString("标准件长度"));
        return attr;
    }

    public String buildAttr() {
        JSONObject object = new JSONObject();
        if (StringUtils.isNotBlank(caizhi)) object.put("材质", caizhi);
        if (StringUtils.isNotBlank(hou)) object.put("厚", hou);
        if (StringUtils.isNotBlank(kuan)) object.put("宽", kuan);
        if (StringUtils.isNotBlank(chang)) object.put("长", chang);
        if (StringUtils.isNotBlank(pinpai)) object.put("品牌", pinpai);
        if (StringUtils.isNotBlank(guigexinghao)) object.put("规格型号", guigexinghao);
        if (StringUtils.isNotBlank(kucunxiangmu)) object.put("库存项目", kucunxiangmu);
        if (StringUtils.isNotBlank(fushi)) object.put("复试", fushi);
        if (StringUtils.isNotBlank(kucunbeizhu)) object.put("库存备注", kucunbeizhu);
        if (StringUtils.isNotBlank(baozhuangfangshi)) object.put("包装方式", baozhuangfangshi);
        if (StringUtils.isNotBlank(pohaozhuangpei)) object.put("PO号装配", pohaozhuangpei);
        if (StringUtils.isNotBlank(paihao)) object.put("牌号", paihao);
        if (StringUtils.isNotBlank(biaozhunjianguige)) object.put("标准件规格", biaozhunjianguige);
        if (StringUtils.isNotBlank(xingnengdengji)) object.put("性能等级", xingnengdengji);
        if (StringUtils.isNotBlank(biaomianchuli)) object.put("表面处理", biaomianchuli);//名称
        if (StringUtils.isNotBlank(biaomianchuliBm)) object.put("表面处理编码", biaomianchuliBm);//名称
        if (StringUtils.isNotBlank(guigepinpai)) object.put("规格/品牌", guigepinpai);
        if (StringUtils.isNotBlank(xinghaocaizhi)) object.put("型号/材质", xinghaocaizhi);
        if (StringUtils.isNotBlank(sehao)) object.put("色号", sehao);
        if (StringUtils.isNotBlank(teshuyaoqiu)) object.put("特殊要求", teshuyaoqiu);
        if (StringUtils.isNotBlank(biaozhunjianchangdu)) object.put("标准件长度", biaozhunjianchangdu);
        return object.toJSONString();
    }


    public String buildAttrOrigin() {
        JSONArray array = new JSONArray();
        if (StringUtils.isNotBlank(caizhi)) {
            JSONObject object = new JSONObject();
            object.put("name", "材质");
            object.put("value", caizhi);
            array.add(object);
        }

        if (StringUtils.isNotBlank(hou)) {
            JSONObject object = new JSONObject();
            object.put("name", "厚");
            object.put("value", hou);
            array.add(object);
        }

        if (StringUtils.isNotBlank(kuan)) {
            JSONObject object = new JSONObject();
            object.put("name", "宽");
            object.put("value", kuan);
            array.add(object);
        }

        if (StringUtils.isNotBlank(chang)) {
            JSONObject object = new JSONObject();
            object.put("name", "长");
            object.put("value", chang);
            array.add(object);
        }

        if (StringUtils.isNotBlank(pinpai)) {
            JSONObject object = new JSONObject();
            object.put("name", "品牌");
            object.put("value", pinpai);
            array.add(object);
        }

        if (StringUtils.isNotBlank(guigexinghao)) {
            JSONObject object = new JSONObject();
            object.put("name", "规格型号");
            object.put("value", guigexinghao);
            array.add(object);
        }

        if (StringUtils.isNotBlank(kucunxiangmu)) {
            JSONObject object = new JSONObject();
            object.put("name", "库存项目");
            object.put("value", kucunxiangmu);
            array.add(object);
        }

        if (StringUtils.isNotBlank(fushi)) {
            JSONObject object = new JSONObject();
            object.put("name", "复试");
            object.put("value", fushi);
            array.add(object);
        }


        if (StringUtils.isNotBlank(kucunbeizhu)) {
            JSONObject object = new JSONObject();
            object.put("name", "库存备注");
            object.put("value", kucunbeizhu);
            array.add(object);
        }

        if (StringUtils.isNotBlank(baozhuangfangshi)) {
            JSONObject object = new JSONObject();
            object.put("name", "包装方式");
            object.put("value", baozhuangfangshi);
            array.add(object);
        }

        if (StringUtils.isNotBlank(pohaozhuangpei)) {
            JSONObject object = new JSONObject();
            object.put("name", "PO号装配");
            object.put("value", pohaozhuangpei);
            array.add(object);
        }

        if (StringUtils.isNotBlank(paihao)) {
            JSONObject object = new JSONObject();
            object.put("name", "牌号");
            object.put("value", paihao);
            array.add(object);
        }

        if (StringUtils.isNotBlank(biaozhunjianguige)) {
            JSONObject object = new JSONObject();
            object.put("name", "标准件规格");
            object.put("value", biaozhunjianguige);
            array.add(object);
        }

        if (StringUtils.isNotBlank(xingnengdengji)) {
            JSONObject object = new JSONObject();
            object.put("name", "性能等级");
            object.put("value", xingnengdengji);
            array.add(object);
        }

        if (StringUtils.isNotBlank(biaomianchuli)) {
            JSONObject object = new JSONObject();
            object.put("name", "表面处理");
            object.put("value", biaomianchuli);
            array.add(object);
        }


        if (StringUtils.isNotBlank(guigepinpai)) {
            JSONObject object = new JSONObject();
            object.put("name", "规格/品牌");
            object.put("value", guigepinpai);
            array.add(object);
        }

        if (StringUtils.isNotBlank(xinghaocaizhi)) {
            JSONObject object = new JSONObject();
            object.put("name", "型号/材质");
            object.put("value", xinghaocaizhi);
            array.add(object);
        }

        if (StringUtils.isNotBlank(sehao)) {
            JSONObject object = new JSONObject();
            object.put("name", "色号");
            object.put("value", sehao);
            array.add(object);
        }

        if (StringUtils.isNotBlank(teshuyaoqiu)) {
            JSONObject object = new JSONObject();
            object.put("name", "特殊要求");
            object.put("value", teshuyaoqiu);
            array.add(object);
        }

        if (StringUtils.isNotBlank(biaozhunjianchangdu)) {
            JSONObject object = new JSONObject();
            object.put("name", "标准件长度");
            object.put("value", biaozhunjianchangdu);
            array.add(object);
        }
        return array.toJSONString();
    }

    public String buildProp() {
        String prop = "";
        if (StringUtils.isNotBlank(caizhi)) prop = getProp(prop, caizhi);
        if (StringUtils.isNotBlank(hou)) prop = getProp(prop, hou);
        if (StringUtils.isNotBlank(kuan)) prop = getProp(prop, kuan);
        if (StringUtils.isNotBlank(chang)) prop = getProp(prop, chang);
        if (StringUtils.isNotBlank(pinpai)) prop = getProp(prop, pinpai);
        if (StringUtils.isNotBlank(guigexinghao)) prop = getProp(prop, guigexinghao);
        if (StringUtils.isNotBlank(kucunxiangmu)) prop = getProp(prop, kucunxiangmu);
        if (StringUtils.isNotBlank(fushi)) prop = getProp(prop, fushi);
        if (StringUtils.isNotBlank(kucunbeizhu)) prop = getProp(prop, kucunbeizhu);
        if (StringUtils.isNotBlank(baozhuangfangshi)) prop = getProp(prop, baozhuangfangshi);
        if (StringUtils.isNotBlank(pohaozhuangpei)) prop = getProp(prop, pohaozhuangpei);
        if (StringUtils.isNotBlank(paihao)) prop = getProp(prop, paihao);
        if (StringUtils.isNotBlank(biaozhunjianguige)) prop = getProp(prop, biaozhunjianguige);
        if (StringUtils.isNotBlank(xingnengdengji)) prop = getProp(prop, xingnengdengji);
        if (StringUtils.isNotBlank(biaomianchuli)) prop = getProp(prop, biaomianchuli);
        if (StringUtils.isNotBlank(guigepinpai)) prop = getProp(prop, guigepinpai);
        if (StringUtils.isNotBlank(xinghaocaizhi)) prop = getProp(prop, xinghaocaizhi);
        if (StringUtils.isNotBlank(sehao)) prop = getProp(prop, sehao);
        if (StringUtils.isNotBlank(teshuyaoqiu)) prop = getProp(prop, teshuyaoqiu);
        if (StringUtils.isNotBlank(biaozhunjianchangdu)) prop = getProp(prop, biaozhunjianchangdu);
//        if (StringUtils.isNotBlank(biaomianchuliBm)) prop = getProp(prop, biaomianchuliBm);
        return prop;
    }

    /**
     * 钢材库构建辅助属性
     * @return
     */
    public String buildGCProp() {
        String prop = "";
        if (StringUtils.isNotBlank(caizhi)) prop = getProp(prop, caizhi);
        if (StringUtils.isNotBlank(hou)) prop = getProp(prop, hou);
        if (StringUtils.isNotBlank(chang)) prop = getProp(prop, chang);
        if (StringUtils.isNotBlank(kuan)) prop = getProp(prop, kuan);
        if (StringUtils.isNotBlank(kucunxiangmu)) prop = getProp(prop, kucunxiangmu);
        return prop;
    }

    /**
     * 型材库构建辅助属性
     * @return
     */
    public String buildXcProp() {
        String prop = "";
        if (StringUtils.isNotBlank(caizhi)) prop = getProp(prop, caizhi);
        if (StringUtils.isNotBlank(guigexinghao)) prop = getProp(prop, guigexinghao);
        return prop;
    }

    /**
     * 油漆库构建辅助属性
     * @return
     */
    public String buildYQProp() {
        String prop = "";;
        if (StringUtils.isNotBlank(pinpai)) prop = getProp(prop, pinpai);
        if (StringUtils.isNotBlank(paihao)) prop = getProp(prop, paihao);
        if (StringUtils.isNotBlank(sehao)) prop = getProp(prop, sehao);
        return prop;
    }

    public String getProp(String prop, String itemAttr) {
        if (StringUtils.isNotEmpty(prop)) {
            prop = prop + "." + itemAttr;
        } else {
            prop = itemAttr;
        }
        return prop;
    }
}
